<template>
  <view class="home-page">
    <!-- 顶部 KV 图 -->
    <image class="kv-img-h" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/kkk.jpg" mode="widthFix"></image>
    <!-- 简介模块 -->
    <view class="intro-section">
  <text class="intro-text">
    全国青少年高尔夫球锦标赛创立于1995年，由中国高尔夫球协会主办，朝向集团自2004年持续承办至今。作为亚洲规模最大、历史最悠久的青少年高尔夫赛事，三十一载深耕，赛事覆盖全国34省及港澳台地区、参赛规模不断跃升，铸就中国高尔夫“人才摇篮”！它不仅见证了一代代球员的成长，更强力输送了大批优秀选手，擎动中国高尔夫运动蓬勃发展！
  </text>
    </view>
    <!-- 分组标题 -->
    <view class="group-title">
      <image class="group-title-bg" :src="groupimg" mode="widthFix"></image>
    </view>
    <!-- 六个按钮 -->
    <view class="btn-grid">
      <view class="btn-item purple" @click="onBtnClick('ssguiz')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_ssgc.png" mode="" />
      </view>
      <view class="btn-item blue" @click="onBtnClick('ssrc')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_ssrc.png" mode="" />
      </view>
      <view class="btn-item cyan" @click="onBtnClick('fenzb')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_fzb.png" mode="" />
      </view>
      <view class="btn-item orange" @click="onBtnClick('cjb')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_cjb.png" mode="" />
      </view>
      <view class="btn-item blue2" @click="onBtnClick('dwt')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_dwt.png" mode="" />
      </view>
      <view class="btn-item red" @click="onBtnClick('qcgl')">
        <image class="btn-icon" src="https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/icon_qcgl.png" mode="" />
      </view>
    </view>
    <CustomTabbar :current="0"  @change="onTabChange"/>
  </view>
</template>
<script>
import CustomTabbar from '@/components/CustomTabbar.vue'
export default {
  components: { CustomTabbar },
  data(){
	return {
    groupimg: '',
    groupType: '', //AB CD组
    qcgl_link_url: '',
    jsgz_link_url: ''
	}  
  },
  methods: {
    onBtnClick(page) {
      console.log('-----------2page-----------', page)
      // if(page == 'qcgl') {
      //   window.open(this.qcgl_link_url)
      //   return
      // }
      // if(page == 'ssguiz') {
      //   window.open(this.jsgz_link_url)
      //   return
      // }
      uni.navigateTo({
        url: `/pages/${page}/index?group=${this.groupType}`
      })
    },
    onTabChange(index,file) {
      console.log('切换到了第', index + 1, '个 tab', file)
      if (index == 1) {
        // 关闭所有页面 跳转 pages/index/index
        uni.reLaunch({ url: '/pages/index/index' })
        return
      }
       uni.navigateTo({ url: `/pages/${file}/index?group=${this.groupType}` })
    },
       async fetchNews() {
      try {
        const res = await uni.request({
          url: 'http://chaoxiang.scoringchina.com/index/api/gonglve',
          method: 'GET'
        });
        if(res && res.data && res.data.code === 1) {
          this.qcgl_link_url = res.data.data.link_url;
          if(this.link_url) {
            window.open(this.link_url);
          }

        } else {
          console.error('获取数据失败', res[1]);
        }
      } catch (error) {
        console.error('请求异常', error);
      }
    },
      async fetchNews2() {
      try {
        const res = await uni.request({
          url: 'http://chaoxiang.scoringchina.com/index/api/guizhang',
          method: 'GET'
        });
        if(res && res.data && res.data.code === 1) {
          this.jsgz_link_url = res.data.data.link_url || "";
        } else {
          console.error('获取数据失败', res[1]);
        }
      } catch (error) {
        console.error('请求异常', error);
      }
    },
 
  },
  onLoad(e) {
    console.log('-----------1-----------', e.group)
    this.groupType = e.group
	if(e.group=='AB组'){
		this.groupimg = 'https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/AB_n.png'
	}else {
		this.groupimg = 'https://scoringchina.oss-cn-beijing.aliyuncs.com/biemlfGolf/CD_n.png'
  }
    this.fetchNews()
  this.fetchNews2()
	uni.setNavigationBarTitle({
		title:e.group + '赛事信息'
	})
  },
}
</script>
<style scoped>
.home-page {
  background: #fff;
  min-height: 100vh;
  padding-bottom: 120rpx;
  box-sizing: border-box;
}
.kv-img-h {
  width: 100vw;
  height: 300rpx;
  object-fit: cover;
  display: block;
}
.intro-section {
  width: 95vw;
  background: #fff;
  border-radius: 12rpx;
  padding: 0rpx 18rpx;
  color: #222;
  font-size: 28rpx;
  line-height: 1.8;
}
.group-title {
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  
  position: relative;
  height: 100rpx;
}
.group-title-bg {
  width: 320rpx;
  height: 106rpx;

}
.group-title-text {
  font-size: 40rpx;
  font-weight: bold;
  color: #fff;
  z-index: 2;
  position: relative;
  letter-spacing: 4rpx;
}
.btn-grid {
  width: 92vw;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0rpx 14rpx;
  justify-content: center;
}
.btn-item {
  width: 48%;
  height: 140rpx;
  border-radius: 18rpx;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  margin-bottom: 0;
  cursor: pointer;
}
.btn-icon {
  width: 100%;
  height: 100%;
  
}
.btn-label {
  font-size: 32rpx;
  font-weight: bold;
  color: #fff;
}

.intro-text{
  text-indent: 2em; 
  display: block;
}
</style>